'use strict';

module.exports = app => {
  const { STRING, INTEGER, DATE } = app.Sequelize;

  const sys_post = app.model.define('sys_post', {
    postId: {
      type: INTEGER(20),
      comment: "岗位ID",
      allowNull:false,
      primaryKey: true,
      autoIncrement: true,
      field:"post_id"
    },
    postCode:{
      type:STRING(64),
      comment:"岗位编码",
      allowNull:false,
      field:"post_code"
    },
    postName:{
      type:STRING(50),
      comment:"岗位名称",
      allowNull:false,
      field:"post_name"
    },
    postSort:{
      type:INTEGER(4),
      comment:"显示顺序",
      allowNull:false,
      field:"post_sort"
    },
    status:{
      type:STRING(1),
      comment:"状态（0正常 1停用）",
      allowNull:false
    },
    createBy:{
      type:STRING(64),
      comment:"创建者",
      defaultValue:"",
      field:"create_by"
    },
    updateBy:{
      type:STRING(64),
      comment:"更新者",
      defaultValue:"",
      field:"update_by"
    },
    remark:{
      type:STRING(500),
      comment:"备注",
      defaultValue:""
    },
    createTime:{
      type:DATE,
      comment:"创建时间",
      field:"created_at"
    }
  },{
    paranoid:true,
    freezeTableName:true
  });

  sys_post.associate = ()=>{
    app.model.SysPost.belongsToMany(app.model.SysUser,{
      through:app.model.SysUserPost
    });
  };

  return sys_post;
};